WEBVTT

00:00.650 --> 00:02.200
Welcome back to our costs.

00:02.210 --> 00:07.130
So this session provides you with a quick overview over the data type tuple.

00:07.410 --> 00:14.080
So a tuple you can store many other objects and therefore tuple is also a sequence of many elements

00:14.090 --> 00:15.860
like for example a list.

00:16.370 --> 00:19.860
So to put this in some ways comparable to our list.

00:20.390 --> 00:27.290
However a tuple has much less functionality than a list and therefore we don't use it as often and as

00:27.290 --> 00:29.450
much as we we the list.

00:29.450 --> 00:35.330
But however there are many situations in Python programming where we we get in touch with tuples so

00:35.330 --> 00:40.730
we should at least know the basic functionality and the basics of tuples.

00:40.760 --> 00:41.140
All right.

00:41.150 --> 00:48.960
So let's start creating our first tuple by creating of our able a A equals and pattern to this one two

00:49.000 --> 00:49.380
three

00:52.150 --> 00:59.280
so a s a tuple containing three elements One two and three and we can also create a tuple without use.

00:59.290 --> 01:03.880
So if you just type B equals one two three is separated by Hamas.

01:03.940 --> 01:12.250
This also works and the same s with lists you can put the many different data types and many different

01:12.280 --> 01:13.650
elements into a tuple.

01:13.660 --> 01:20.620
So for example let's create a tuple C C equals 1 2.5 and talk.

01:20.620 --> 01:27.850
So we have feared integer we have a float and we have a string object so that's no problem it works

01:27.850 --> 01:36.330
like in the list and we can also index the tuple like in the list let's say if you want to get the second

01:36.390 --> 01:42.750
element of our tuple at an exposition one I would expect to get them to

01:45.500 --> 01:47.020
exactly.

01:47.300 --> 01:54.950
And also slicing works the same way as both lists if you want to slice tuple C from the second element.

01:54.950 --> 02:00.020
So beginning from index position 1 until the very last element.

02:00.080 --> 02:01.380
Then this also works.

02:01.520 --> 02:06.910
And also if we multiply a tuple with an integer eight times two.

02:07.040 --> 02:15.500
So we have the same behavior as the lists that actually we create copies of A and concatenate the copies

02:16.290 --> 02:21.860
so we don't have element y's multiplication as one one might expect actually.

02:21.870 --> 02:28.250
And also we can concatenate to 2:00 so we have total a and we f and number tuple with the elements for

02:28.260 --> 02:29.250
5 6.

02:29.410 --> 02:36.160
Then we can just concatenate it to a large Topo and the most important difference between a total and

02:36.160 --> 02:36.560
a list.

02:36.560 --> 02:41.350
This that the list is mutable so you can change elements of a list.

02:41.590 --> 02:50.150
And this is not possible with a total so if you want to change the first element of tuple a let's say

02:50.160 --> 02:58.160
change it to 100 then Python drops us an error message so tuple object does not some plot item assignment.

02:58.170 --> 03:03.650
So our total is immutable and this heavily restricts the functionality of tuples.

03:03.660 --> 03:07.120
So there are no not too much cases where we need tuples.

03:07.140 --> 03:12.890
However in python there are many functions that return multiple values.

03:12.910 --> 03:21.900
And so if a function returns multiple values it's in most cases it returns that via returning a tuple

03:21.900 --> 03:26.350
of these multiple elements so let's let's have an example here.

03:26.370 --> 03:30.040
So let's create the list with five elements.

03:30.120 --> 03:30.880
List El.

03:31.080 --> 03:34.820
And now we apply the function enumerate on Al.

03:34.860 --> 03:40.780
So what enumerate actually does the stocks index and value pass of list.

03:40.790 --> 03:43.110
L So actually it stops.

03:43.350 --> 03:51.540
So we have fear element one at an exposition from 0 and enumerate stores 0 1.

03:51.540 --> 03:53.820
So in exposition 0 now.

03:53.830 --> 04:04.110
So the element 1 then at an exposition 1 this element to enumerate creates and starts the index while

04:04.110 --> 04:07.250
you pass off a list.

04:07.260 --> 04:13.320
So and if I run now the enumerate function pacing does not return the index so well you pass.

04:13.320 --> 04:16.030
So it's only creating a so-called iterator.

04:16.050 --> 04:23.490
So what is an Iterator iterator we will learn later more about iterate us but to put it in easy words

04:23.880 --> 04:26.820
by running enumerate we are telling python.

04:27.210 --> 04:33.380
So please python and make yourself ready to give me the index value you pass at the time that I need

04:33.380 --> 04:33.850
it.

04:33.990 --> 04:40.200
So but now at this step it does not create and store the past it only creates the value you pass if

04:40.200 --> 04:44.760
I explicitly call it in another step and I can do it here.

04:44.760 --> 04:49.660
In this case by applying the list function on our iterator object.

04:49.680 --> 04:55.800
So now let's apply the list function on our enumerate object and assign the arrival n

04:58.690 --> 05:06.400
and now we get a list with the five elements and these elements tuples and these are tuples of indexed

05:06.400 --> 05:07.280
value pass.

05:07.300 --> 05:15.010
So we have that indexed position 0 the element 1 We are fed index position 1 The Element 2 and so on

05:15.120 --> 05:20.470
at the index position far the element 5 and this is one example of where we get in touch with tuples.

05:20.470 --> 05:26.140
So even if you if you don't want to get in touch with two bits there are many functions that return

05:26.140 --> 05:31.360
to both actually and then let's slice them the first tuple here.

05:31.750 --> 05:39.510
Let's say we take the first tuple at an exposition 0 and call it first tuple.

05:39.570 --> 05:47.610
So now we have one tuple of with the elements 0 and 1 and then what we can do we can unpack a tuple

05:47.820 --> 05:55.490
by saying Okay the first element I call index and the second element I will call a value so index comma

05:55.530 --> 06:03.540
value is equal to first tuple and now if you print index and value we get the unpacked three elements

06:03.540 --> 06:04.250
of the tuple.

06:04.260 --> 06:13.730
So index is 0 and values 1 in but we can also do we can let's call again our list l we can transform

06:13.730 --> 06:16.710
a list into a tuple so that's that's also possible.

06:17.670 --> 06:20.780
So now we have a tuple with five elements.

06:20.810 --> 06:21.150
All right.

06:21.150 --> 06:23.460
So this was a quick overview of our tuples.

06:23.460 --> 06:24.260
Hope you enjoyed it.

06:24.270 --> 06:28.110
And yeah we see us in the next session about sets.
